from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Date
from sqlalchemy.orm import relationship

from .database import Base


class Rule(Base):
    __tablename__ = "Rule"
    target = Column(String, primary_key=True, index=True)
    max = Column(String, index=True)
    min = Column(String, index=True)

    def __repr__(self):
        return {self.target, self.min, self.max}


class Version(Base):
    __tablename__ = "version"

    id = Column(Integer, primary_key=True, index=True)
    bid = Column(String, index=True)
    version = Column(Integer)
    md5 = Column(String)
    download_url = Column(String)
    max_os_api = Column(Integer)
    min_os_api = Column(Integer)
    max_version = Column(Integer)
    min_version = Column(Integer)
    cpu_arch = Column(String)
    channel = Column(String)
    platform = Column(String)
    pop_count = Column(Integer)
    install_count = Column(Integer)
    aid = Column(Integer)
    create_time = Column(Date)
    delete_time = Column(Date)
    is_delete = Column(Boolean)
    is_release = Column(Boolean)

    def __repr__(self):
        return self


class VersionMessage(Base):
    __tablename__ = "version_message"

    id = Column(Integer, primary_key=True, index=True)
    bid = Column(String)
    user_bid = Column(String)
    version = Column(Integer)
    version_bid = Column(String)
    operation = Column(Integer)
    content = Column(String)
    create_time = Column(Date)

    def __repr__(self):
        return self
